package com.up.blog.controller;

import com.alibaba.fastjson.JSON;
import com.up.blog.domain.Messagebean;
import com.up.blog.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@Controller
public class MessageController  {
    @Autowired
    private MessageService messageService;
    @RequestMapping(value = "/getmessage", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String findUserById(HttpServletRequest req, HttpServletResponse resp) {
        String mess=req.getParameter("id");
        System.out.println(mess);
        String ret=null;
        try {
            List<Messagebean> ms= messageService.getMessages(mess);
            ret=JSON.toJSONString(ms);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ret;
    }
}